package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LXW
 * Date: 2022-03-21
 * Time: 21:36
 */
public class Demo5 {

    public static  boolean flag = false;
    public static void main(String[] args) {

        Thread t = new Thread(() -> {
            while (!flag) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();
        try {
            t.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        flag = true;
    }
}
